package ltd.bugs.cute.common.extention.factory;

import ltd.bugs.cute.common.extention.annotation.SpringBean;
import ltd.bugs.cute.common.extention.factory.impl.JdkExtensionFactory;
import ltd.bugs.cute.common.extention.factory.impl.SpringExtensionFactory;

public class ExtensionFactory {

  /**
   * 获取对应类型的实例 检查当前扩展节点是否注解了@SpringBean
   * 
   * 1、注解了@SpringBean，从spring context加载出来
   * 
   * 2、没有注解，通过无参构造方法进行实例化
   * 
   * @param type
   * @return
   * @throws Exception
   */
  public static <T> T getInstance(Class<T> type) throws Exception {
    if (type.isAnnotationPresent(SpringBean.class)) {
      return SpringExtensionFactory.newInstance(type);
    }

    return JdkExtensionFactory.newInstance(type);
  }
}
